package cn.com.b2office.struts2.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.com.b2office.domain.MemberAddress;
import cn.com.b2office.domain.Order;
import cn.com.b2office.domain.OrderItem;
import cn.com.b2office.domain.User;
import cn.com.b2office.service.MemberService;
import cn.com.b2office.service.OrderService;

import com.opensymphony.xwork2.ActionSupport;

public class ViewOrderDeatailAction extends ActionSupport implements
		SessionAware {

	private static final long serialVersionUID = 5100452064095491275L;

	private OrderService orderService = null;

	private MemberService memberService = null;

	private Map session = null;

	private String orderId = null;

	private String message = null;

	private Order order = null;

	private List<OrderItem> orderItems = null;

	private String address = null;

	public void setSession(Map session) {
		this.session = session;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public String execute() throws Exception {
		User user = (User) session.get("user");
		if (user == null)
			return "login";
		if (orderId == null || orderId.trim().equals("")) {
			message = "orderId 为空,参数不正确.";
			return "message";
		}
		order = orderService.getOrder(orderId);
		orderItems = orderService.getOrderItems(orderId);

		if (order == null || orderItems == null || orderItems.isEmpty()) {
			message = "找不到OrderId=" + orderId + "的订单.";
			return "message";
		}

		MemberAddress memberAddress = memberService.getMemberAddress(order
				.getReceiveAddrId());
		if (memberAddress != null)
			address = memberService.translateAddress(memberAddress);

		return SUCCESS;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getOrderId() {
		return orderId;
	}

	public String getMessage() {
		return message;
	}

	public Order getOrder() {
		return order;
	}

	public List<OrderItem> getOrderItems() {
		return orderItems;
	}

	public String getAddress() {
		return address;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

}
